import { Auths } from '@/modules/guard'
import { RoleService, UserLoginService, UserService } from '@/service'
import { Body, Controller, Headers, Post, UseGuards } from '@nestjs/common'
import { GetOneDto, LoginDTO } from './user.dto'

@Controller('user')
export class UserControllers {
    constructor(
        private readonly userLoginService: UserLoginService,
        private readonly userService: UserService,
        private readonly roleService: RoleService,
    ) {}

    @Post('login')
    public async queryQuestion(@Body() body: LoginDTO) {
        return await this.userLoginService.login(body)
    }

    @Post('getToken')
    public async getToken(@Headers('devid') devid: string) {
        return await this.userLoginService.getToken(devid)
    }

    @Post('getOneWithoutSensitive')
    @Auths()
    public async getOneWithoutSensitive(@Body() body: GetOneDto) {
        return await this.userService.getOneWithoutSensitive(body)
    }

    @Post('getOne')
    @Auths()
    public async getOne(@Body() body: GetOneDto) {
        return await this.userService.getOne(body)
    }

    @Post('queryCompanyUser')
    @Auths()
    public async queryCompanyUser(@Body() body: any) {
        return await this.userService.queryCompanyUser(body)
    }

    @Post('getMyInfo')
    @Auths()
    public async getMyInfo(@Body() body: any) {
        return await this.userService.getMyInfo(body)
    }

    @Post('loginout')
    @Auths()
    public async loginout(@Body() body: any, @Headers() headers: any) {
        return await this.userLoginService.loginout(body, headers.devid, headers.Authorization || headers.authorization)
    }

    /**
     * 用户管理页
     * @param body
     */
    @Post('saveUser')
    @Auths()
    public async saveUser(@Body() body: any) {
        return await this.userService.saveUser(body)
    }
    @Post('deleteUser')
    @Auths()
    public async deleteUser(@Body() body: any) {
        return await this.userService.deleteUser(body)
    }
    @Post('editStatus')
    @Auths()
    public async editStatus(@Body() body: any) {
        return await this.userService.editStatus(body)
    }

    /**
     * 角色权限
     * @param body
     */
    @Post('queryMyAction')
    @Auths()
    public async queryMyAction(@Body() body: any) {
        return await this.roleService.queryMyAction(body)
    }
}
